<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>提交文件demo</title>
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <script src="js/jquery.serializejson.js"></script>
    <style>
        #ttbutton{
            text-align: center;
        }
    </style>
    <script>
        $(function () {
            $('#tbutton').click(function () {
                let formData = new FormData($('#tform')[0]);
                $.ajax({
                    url:"/h3",
                    type:"POST",
                    data:formData,
                    contentType:false,
                    // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                    processData:false,
                    cache:false,
                    success:function (data) {
                        console.log(data);
                    }
                })
            })
        })
    </script>
</head>
<body>
<div class="container" id="tregist">
    <div class="row">
        <h1 class="col-md-3 col-md-offset-2">提交文件 <small>The Demo Of Submiting Documents</small></h1>
        <div class="col-md-3" id="warning">
        </div>
    </div>
    <div class="row">
        <form class="col-md-4 col-md-offset-4" id="tform">
            <div class="form-group">
                <label for="username">请输入用户名</label>
                <input type="email" class="form-control" id="username" placeholder="name" name="username">
                <p id="error_username"></p>
            </div>
            <div class="form-group">
                <label for="password">请输入密码</label>
                <input type="password" class="form-control" id="password" placeholder="Password" name="password">
                <p id="error_password"></p>
            </div>
            <div class="form-group">
                <label for="password">请选择文件</label>
                <input type="file" class="form-control-file" id="file" placeholder="上传文件" name="file">
                <p id="error_file"></p>
            </div>
            <div id="ttbutton">
                <button type="button" class="btn btn-primary" id="tbutton">提交文件</button>
            </div>
        </form>
    </div>
</div>
</body>
</html>